home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Data 2002 May / CD Rom Data Mayıs 2002.iso / Freeware / Blitz Basic / data1.cab / Support / help / beginners / tutorial / deepend / 3 - simple file example commented.bb < prev    next >
Encoding:
Text File  |  2002-04-10  |  2.0 KB  |  67 lines

  1.  
  2. ; -------------------------------------------------------------
  3. ; Simple file-reading example, with crude string parsing...
  4. ; -------------------------------------------------------------
  5. ; Uncommented version, to show how simple the code really is...
  6.  
  7. Graphics 640, 480
  8.  
  9. Color 150, 150, 200
  10. Print ; Blank line...
  11. Print "Reading text from 'test.txt'..."
  12.  
  13. Color 255, 255, 255
  14.  
  15. ; -------------------------------------------------------------
  16. ; Attempt to read the file, storing the handle as 'info'...
  17. ; -------------------------------------------------------------
  18.  
  19. info = ReadFile ("test.txt")
  20.  
  21. ; -------------------------------------------------------------
  22. ; If the handle is valid (non-zero), process the file...
  23. ; -------------------------------------------------------------
  24.  
  25. If info
  26.  
  27.     ; ---------------------------------------------------------
  28.     ; Repeat the line-parsing until end-of-file is reached...
  29.     ; ---------------------------------------------------------
  30.  
  31.     Repeat
  32.     
  33.         ; -----------------------------------------------------
  34.         ; Read a line from the file and print it on screen...
  35.         ; -----------------------------------------------------
  36.  
  37.         a$ = ReadLine (info)
  38.         Print a$
  39.  
  40.     ; ---------------------------------------------------------
  41.     ; Repeat above until the next line is true (end-of-file)...
  42.     ; ---------------------------------------------------------
  43.  
  44.     Until Eof (info)
  45.  
  46.     ; ---------------------------------------------------------
  47.     ; Close the file (important!)...
  48.     ; ---------------------------------------------------------
  49.  
  50.     CloseFile info
  51.  
  52.     ; ---------------------------------------------------------
  53.     ; If the file handle was invalid (zero)...
  54.     ; ---------------------------------------------------------
  55.  
  56. Else
  57.  
  58.     RuntimeError "Failed to read test.txt! Aborting..."
  59.     
  60. EndIf
  61.  
  62. ; -------------------------------------------------------------
  63. ; Wait for mouseclick, then quit...
  64. ; -------------------------------------------------------------
  65.  
  66. MouseWait
  67. End